/*
 * Copyright (C) <2013> 神马才注册 <373575012@qq.com>
 *
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.wen.qqrobot;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

/**
 * Created by wenwen on 2016/10/5.
 * version 1.0
 */
public class Config {

    private static class ConfigInstance {

        private static final Config INSTANCE = new Config();
    }

    /**
     * 配置文件地址
     */
    private static final String PROPERTIES = "config.properties";

    private String qq;

    private String password;

    private String shellPassword;

    private boolean sendSingle;

    private boolean sendGroup;

    private String groups;

    private String blacklist;

    private String directory;

    private Config() {
        //读取配置对象
        Properties pro = new Properties();
        try {
            pro.load(new FileInputStream(PROPERTIES));
        } catch (IOException ex) {
            ex.printStackTrace();
            System.exit(1);
        }
        this.setQQ(pro.getProperty("QQ"));
        this.setPassword(pro.getProperty("PASSWORD"));
        this.shellPassword = pro.getProperty("SHELL_PASSWORD", "admin");
        this.sendSingle = Boolean.valueOf(pro.getProperty("SINGLE", "true"));
        this.sendGroup = Boolean.valueOf(pro.getProperty("GROUP", "false"));
        this.groups = pro.getProperty("GROUP_FILTER", "null");
        this.blacklist = pro.getProperty("BLACKLIST", "null");
        this.directory = pro.getProperty("DIRECTORY", "");
    }

    public String getQQ() {
        return qq;
    }

    private void setQQ(String qq) {
        if (qq.isEmpty()) {
            throw new RuntimeException("必须在config.properties中填写QQ号！");
        }
        this.qq = qq;
    }

    public String getPassword() {
        return password;
    }

    private void setPassword(String password) {
        if (password.isEmpty()) {
            throw new RuntimeException("必须在config.properties中填写密码号！");
        }
        this.password = password;
    }

    public String getShellPassword() {
        return shellPassword;
    }

    public void setShellPassword(String shellPassword) {
        this.shellPassword = shellPassword;
    }

    public boolean isSendSingle() {
        return sendSingle;
    }

    public void setSendSingle(boolean sendSingle) {
        this.sendSingle = sendSingle;
    }

    public boolean isSendGroup() {
        return sendGroup;
    }

    public void setSendGroup(boolean sendGroup) {
        this.sendGroup = sendGroup;
    }

    public String getGroups() {
        return groups;
    }

    public void setGroups(String groups) {
        this.groups = groups;
    }

    public String getBlacklist() {
        return blacklist;
    }

    public void setBlacklist(String blacklist) {
        this.blacklist = blacklist;
    }

    public String getDirectory() {
        return directory;
    }

    public void setDirectory(String directory) {
        this.directory = directory;
    }

    public static Config getInstance() {
        return ConfigInstance.INSTANCE;
    }
}
